/**
 * @file lv_100ask_boot_animation.c
 *
 */

/*********************
 *      INCLUDES
 *********************/




#include <stdio.h>
#include "boot_animation.h"

static void set_value(void *bar, int32_t v)
{
    lv_bar_set_value(bar, v, LV_ANIM_OFF);
}

void line_1(void)
{
    /*Create an array for the points of the line*/
    static lv_point_t line_points[] = { {0, 0}, {478, 0}, {478, 853}, {0, 853}, {240, 400} };

    /*Create style*/
    static lv_style_t style_line;
    lv_style_init(&style_line);
    lv_style_set_line_width(&style_line, 1);
    lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_RED));
    lv_style_set_line_rounded(&style_line, true);

    /*Create a line and apply the new style*/
    lv_obj_t * line1;
    line1 = lv_line_create(lv_scr_act());
    lv_line_set_points(line1, line_points, 5);     /*Set the points*/
    lv_obj_add_style(line1, &style_line, 0);
    //lv_obj_center(line1);
	lv_obj_align(line1, LV_ALIGN_TOP_LEFT, 0, 0);
}


/**
 * Local styles
 */
void lv_example_style_red(void)
{
    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_GREEN));
    lv_style_set_border_color(&style, lv_palette_lighten(LV_PALETTE_GREEN, 3));
    lv_style_set_border_width(&style, 3);

    lv_obj_t * obj = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj, &style, 0);

    /*Overwrite the background color locally*/
    lv_obj_set_style_bg_color(obj,lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);

	lv_obj_align(obj, LV_ALIGN_TOP_MID, 0, 100);
    //lv_obj_center(obj);
}

/**
 * Local styles
 */
void lv_example_style_green(void)
{
    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_GREEN));
    lv_style_set_border_color(&style, lv_palette_lighten(LV_PALETTE_GREEN, 3));
    lv_style_set_border_width(&style, 3);

    lv_obj_t * obj = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj, &style, 0);

    /*Overwrite the background color locally*/
    lv_obj_set_style_bg_color(obj,lv_palette_main(LV_PALETTE_GREEN), LV_PART_MAIN);

	//lv_obj_align(obj, LV_ALIGN_TOP_MID, 0, 100);
    lv_obj_center(obj);
}

/**
 * Local styles
 */
void lv_example_style_blue(void)
{
    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_GREEN));
    lv_style_set_border_color(&style, lv_palette_lighten(LV_PALETTE_GREEN, 3));
    lv_style_set_border_width(&style, 3);

    lv_obj_t * obj = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj, &style, 0);

    /*Overwrite the background color locally*/
    lv_obj_set_style_bg_color(obj,lv_palette_main(LV_PALETTE_BLUE), LV_PART_MAIN);

	lv_obj_align(obj, LV_ALIGN_BOTTOM_MID, 0, -100);
    //lv_obj_center(obj);
}



void lv_100ask_boot_animation(void (*end_cb)(lv_anim_t *), uint32_t boot_time)
{
    static lv_style_t style_bar_bg;
    static lv_style_t style_indic;

    /**/
    lv_style_init(&style_bar_bg);
    lv_style_set_border_color(&style_bar_bg, lv_palette_main(LV_PALETTE_BLUE));
    lv_style_set_border_width(&style_bar_bg, 2);
    lv_style_set_pad_all(&style_bar_bg, 5); /*To make the indicator smaller*/
    lv_style_set_radius(&style_bar_bg, 6);

    lv_style_init(&style_indic);
    lv_style_set_bg_opa(&style_indic, LV_OPA_COVER);
    lv_style_set_bg_color(&style_indic, lv_palette_main(LV_PALETTE_BLUE));
    lv_style_set_radius(&style_indic, 3);

    /* 主面板 */
    lv_obj_t * panel = lv_obj_create(lv_scr_act());
    lv_obj_set_size(panel, LV_PCT(100), LV_PCT(100));
    lv_obj_set_style_bg_color(panel, lv_color_hex(0xffffff), 0);
    lv_obj_set_style_radius(panel, 0, 0);

    lv_obj_t * bar = lv_bar_create(panel);
    lv_obj_add_style(bar, &style_bar_bg, 0);
    lv_obj_add_style(bar, &style_indic, LV_PART_INDICATOR);
    lv_obj_set_size(bar, 400, 15);
    lv_obj_align(bar, LV_ALIGN_BOTTOM_MID, 0, 0);

	lv_example_style_red();
	lv_example_style_green();
	lv_example_style_blue();

    //lv_obj_t * img = lv_img_create(panel);
    //lv_obj_set_size(img, 480,500);
    //lv_obj_align(img, LV_ALIGN_TOP_LEFT, 0, 0);
    //lv_img_set_src(img, "./icon/boot.png");

    lv_anim_t a_bar;
    lv_anim_init(&a_bar);
    lv_anim_set_var(&a_bar, bar);
    lv_anim_set_values(&a_bar, 0, 100);
    lv_anim_set_exec_cb(&a_bar, set_value);
    lv_anim_set_ready_cb(&a_bar, end_cb);
    lv_anim_set_time(&a_bar, boot_time);
    lv_anim_set_playback_time(&a_bar, 2000);
    lv_anim_start(&a_bar);
}



